package com.isnmp.common.base;

import java.io.PrintStream;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.URL;
import java.security.MessageDigest;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Random;
import java.util.ResourceBundle;
import java.util.UUID;
import java.util.prefs.Preferences;
import javax.swing.Action;
import javax.swing.ImageIcon;

public class Utils {
    static ResourceBundle res = ResourceBundle.getBundle("com.isnmp.common.base.Res");
    static MessageDigest md5 = null;
    static char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };

    static {
        try {
            md5 = MessageDigest.getInstance("MD5");
        } catch (Exception localException) {
            MyLog.err("Get MD5 Function Erro:" + localException.getMessage());
        }
    }

    public static boolean getosInfo(String paramString) {
        boolean bool = true;
        try {
            String str1 = new String(new char[] { 'f', 'u', 't' });
            long l1 = 15552000000L;
            Preferences localPreferences = Preferences.userRoot().node(paramString);
            SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("ddMMyyyydd");
            String str2 = localPreferences.get(str1, "");
            if (str2.equalsIgnoreCase("")) {
                str2 = localSimpleDateFormat.format(new java.util.Date());
                localPreferences.put(str1, str2);
            } else {
                try {
                    localSimpleDateFormat.parse(localPreferences.get(str1, ""));
                } catch (Exception localException1) {
                    str2 = localSimpleDateFormat.format(new java.util.Date());
                    localPreferences.put(str1, str2);
                }
            }
            long l2 = localSimpleDateFormat.parse(str2).getTime();
            if (l2 > System.currentTimeMillis())
                bool = false;
            if (System.currentTimeMillis() - l2 > l1)
                bool = false;
        } catch (Exception localException2) {
            return false;
        }
        return bool;
    }

    public static String classNameToNoPackageName(String paramString) {
        String str = null;
        int i = paramString.lastIndexOf(".");
        if (i > 0) {
            str = paramString.substring(i + 1);
            return str;
        }
        return paramString;
    }

    public static void setActionIcon(Action paramAction, String paramString) {
        try {
            URL localURL = Utils.class.getClassLoader().getResource(paramString);
            ImageIcon localImageIcon = new ImageIcon(localURL);
            paramAction.putValue("SmallIcon", localImageIcon);
        } catch (Exception localException) {
            localException.printStackTrace();
        }
    }

    public static String classToNoPackageName(Object paramObject) {
        return classNameToNoPackageName(paramObject.getClass().getName());
    }

    public static String objToClasssName(Object paramObject) {
        return paramObject.getClass().getName();
    }

    public static synchronized long getTimeIDKey() {
        long l1 = System.currentTimeMillis();
        long l2 = new Random(872L).nextLong();
        long l3 = UUID.randomUUID().getLeastSignificantBits();
        return l1 * l2 * l3;
    }

    public static synchronized String getMD5IDKey(String paramString) {
        if (md5 != null) {
            md5.update(paramString.getBytes());
            byte[] arrayOfByte = md5.digest();
            char[] arrayOfChar = new char[32];
            int i = 0;
            for (int j = 0; j < 16; j++) {
                int k = arrayOfByte[j];
                arrayOfChar[(i++)] = hexDigits[(k >>> 4 & 0xF)];
                arrayOfChar[(i++)] = hexDigits[(k & 0xF)];
            }
            return new String(arrayOfChar);
        }
        return paramString;
    }

    public static String secondToShowString(long paramLong) {
        return null;
    }

    public static String fluxToShowString(int paramInt) {
        return null;
    }

    public static void main(String[] paramArrayOfString) {
        System.out.println(getMD5IDKey("0"));
        System.out.println(getMD5IDKey("1"));
    }

    public static String toUIStr(int paramInt) {
        if (paramInt == -2147483648)
            return "";
        return paramInt + "";
    }

    public static int uiStrToInt(String paramString) {
        if ((paramString == null) || (paramString.equals("")))
            return -2147483648;
        int i = Integer.parseInt(paramString);
        return i;
    }

    public static void initObjectValue(Object paramObject) {
        try {
            Class localClass1 = paramObject.getClass();
            Field[] arrayOfField = localClass1.getDeclaredFields();
            Random localRandom = new Random(24234243L);
            for (int i = 0; i < arrayOfField.length; i++) {
                Field localField = arrayOfField[i];
                Class localClass2 = localField.getType();
                String str1 = localClass2.getName();
                String str2 = localField.getName();
                Class[] arrayOfClass = { localClass2 };
                String str3 = str2.replaceFirst(str2.substring(0, 1), str2.substring(0, 1).toUpperCase());
                Method localMethod = localClass1.getMethod("set" + str3, arrayOfClass);
                Object[] arrayOfObject;
                if (str1.equalsIgnoreCase("int")) {
                    arrayOfObject = new Object[] { new Integer(localRandom.nextInt()) };
                    localMethod.invoke(paramObject, arrayOfObject);
                } else if (str1.equalsIgnoreCase("java.lang.String")) {
                    arrayOfObject = new Object[] { localField.getName() };
                    localMethod.invoke(paramObject, arrayOfObject);
                } else if (str1.equalsIgnoreCase("java.sql.Timestamp")) {
                    arrayOfObject = new Object[] { new Timestamp(System.currentTimeMillis()) };
                    localMethod.invoke(paramObject, arrayOfObject);
                } else if (str1.equalsIgnoreCase("java.sql.Date")) {
                    arrayOfObject = new Object[] { new java.sql.Date(System.currentTimeMillis()) };
                    localMethod.invoke(paramObject, arrayOfObject);
                } else if (str1.equalsIgnoreCase("long")) {
                    arrayOfObject = new Object[] { new Long(localRandom.nextLong()) };
                    localMethod.invoke(paramObject, arrayOfObject);
                } else if (str1.equalsIgnoreCase("boolean")) {
                    arrayOfObject = new Object[] { Boolean.TRUE };
                    localMethod.invoke(paramObject, arrayOfObject);
                }
            }
        } catch (Exception localException) {
            localException.printStackTrace();
        }
    }

    public static void formatObjectString(Object paramObject) {
        try {
            if (paramObject == null)
                return;
            Class localClass1 = paramObject.getClass();
            Field[] arrayOfField = localClass1.getDeclaredFields();
            for (int i = 0; i < arrayOfField.length; i++) {
                Field localField = arrayOfField[i];
                Class localClass2 = localField.getType();
                String str1 = localClass2.getName();
                String str2 = localField.getName();
                Class[] arrayOfClass1 = { localClass2 };
                if (str1.equalsIgnoreCase("java.lang.String")) {
                    String str3 = str2.replaceFirst(str2.substring(0, 1), str2.substring(0, 1).toUpperCase());
                    Class[] arrayOfClass2 = new Class[0];
                    Method localMethod1 = localClass1.getMethod("get" + str3, arrayOfClass2);
                    Object[] arrayOfObject1 = new Object[0];
                    Object localObject = localMethod1.invoke(paramObject, arrayOfObject1);
                    if (localObject == null) {
                        String str4 = str2.replaceFirst(str2.substring(0, 1), str2.substring(0, 1).toUpperCase());
                        Method localMethod2 = localClass1.getMethod("set" + str4, arrayOfClass1);
                        Object[] arrayOfObject2 = { "" };
                        localMethod2.invoke(paramObject, arrayOfObject2);
                    }
                }
            }
        } catch (Exception localException) {
            MyLog.err(res.getString("String_61") + paramObject + res.getString("String_62") + localException.toString());
            MyLog.debug(localException);
        }
    }

    public static void formatObjectString(List paramList) {
        for (int i = 0; i < paramList.size(); i++)
            formatObjectString(paramList.get(i));
    }

    public static void formatObjectString(Object[] paramArrayOfObject) {
        for (int i = 0; i < paramArrayOfObject.length; i++)
            formatObjectString(paramArrayOfObject[i]);
    }
}